package org.xwalk.core.internal;

import android.content.Context;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

public class XWalkDownloadListenerBridge extends XWalkDownloadListenerInternal {
    private XWalkCoreBridge coreBridge;
    private Object wrapper;

    public Object getWrapper() {
        return wrapper;
    }



    public XWalkDownloadListenerBridge(Context context, Object wrapper) {
        super(context);

        this.wrapper = wrapper;
        reflectionInit();

    }

        @Override
    public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
        onDownloadStartStringStringStringStringlongMethod.invoke(url, userAgent, contentDisposition, mimetype, contentLength);
    }


    private ReflectMethod onDownloadStartStringStringStringStringlongMethod = new ReflectMethod(null, "onDownloadStart");


    void reflectionInit() {
        coreBridge = XWalkCoreBridge.getInstance();
        if (coreBridge == null) return;

        onDownloadStartStringStringStringStringlongMethod.init(wrapper, null,
                "onDownloadStart", String.class, String.class, String.class, String.class, long.class);
    }
}
